﻿using AutoMapper;
using AutoMapper.QueryableExtensions;
using Coldairarrow.Business.Aps;
using Coldairarrow.Entity.Aps;
using Coldairarrow.Entity.Base_Manage;
using Coldairarrow.Util;
using EFCore.Sharding;
using LinqKit;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Coldairarrow.Business.Base_Manage
{
    public class APS_OrganizeWorkingTimesDetailBusiness : BaseBusiness<APS_OrganizeWorkingTimesDetail>, IAPS_OrganizeWorkingTimesDetailBusiness, ITransientDependency
    {
        readonly IMapper _mapper;
        public APS_OrganizeWorkingTimesDetailBusiness(IRepository repository, IMapper mapper)
            : base(repository)
        {
            _mapper = mapper;
        }

        #region 外部接口

        public async Task<PageResult<APS_OrganizeWorkingTimesDetail>> GetDataListAsync(PageInput<APS_OrganizeWorkingTimesDetail> input)
        {
            var q = GetIQueryable();
            var where = LinqHelper.True<APS_OrganizeWorkingTimesDetail>();
            var search = input.Search;
            
            if (!search.WorkingTimesID.IsNullOrEmpty())
            {
                where = where.And(x => x.WorkingTimesID==(search.WorkingTimesID));
            }
            //else
            //{
            //    where = where.And(x => string.IsNullOrEmpty(x.WorkingTimesID));
            //}

            if (!search.WorkingDate.IsNullOrEmpty())
            {
                where = where.And(x => x.WorkingDate==(search.WorkingDate));
            }
            if (!search.OrganizeWorkingTimesID.IsNullOrEmpty())
            {
                where = where.And(x => x.OrganizeWorkingTimesID==(search.OrganizeWorkingTimesID));
            }
            if (!search.WorkingTimesDetailID.IsNullOrEmpty())
            {
                where = where.And(x => x.WorkingTimesDetailID == (search.WorkingTimesDetailID));
            }
            if (!search.OrganizeID.IsNullOrEmpty())
            {
                where = where.And(x => x.OrganizeID == (search.OrganizeID));
            }
            if (!search.YearMonth.IsNullOrEmpty())
            {
                where = where.And(x => x.YearMonth == (search.YearMonth));
            }
            return await q.Where(where).GetPageResultAsync(input);
        }

        public async Task<APS_OrganizeWorkingTimesDetail> GetTheDataAsync(string id)
        {
            return await GetEntityAsync(id);
        }

        public async Task AddDataAsync(APS_OrganizeWorkingTimesDetail newData)
        {
            await InsertAsync(newData);
        }

        public async Task UpdateDataAsync(APS_OrganizeWorkingTimesDetail theData)
        {
            await UpdateAsync(theData);
        }

        public async Task DeleteDataAsync(List<string> ids)
        {
            await DeleteAsync(ids);
        }

        #endregion

        #region 私有成员

        #endregion

        #region 数据模型

        #endregion
    }
}